package com.wing.bill.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wing.bill.entity.PurchaseBillReceipt;
import com.wing.bill.service.PurchaseBillReceiptService;
import com.wing.common.utils.JsonResult;
import com.wing.common.utils.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 采购账单发票记录
 *
 * @author xiayang
 */
@Validated
@Api(value = "采购账单发票记录管理", tags = "#/purchase/purchaseBillReceipt")
@RestController("purchaseBillReceiptController")
@RequestMapping("purchase/admin/purchaseBillReceipt")
public class PurchaseBillReceiptController {

    @Resource
    private PurchaseBillReceiptService purchaseBillReceiptService;

    @ApiOperation(value = "查询采购账单发票记录列表", notes = "搜索")
    @GetMapping("/list")
    public PageResult<PurchaseBillReceipt> list(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer limit,
            Long billId) {
        Page<PurchaseBillReceipt> pg = new Page<>(page, limit);
        Map paramMap = new HashMap();
        paramMap.put("billId", billId);
        IPage<PurchaseBillReceipt> list = purchaseBillReceiptService.pageList(pg, paramMap);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }


    @ApiOperation(value = "发票详细", notes = "搜索")
    @GetMapping("/get")
    public JsonResult get(@RequestParam Long id) {
        return JsonResult.success(purchaseBillReceiptService.get(id));
    }


    @ApiOperation(value = "添加发票记录", notes = "添加")
    @PostMapping("/add")
    public JsonResult add(@RequestBody PurchaseBillReceipt purchaseBillReceipt) {
        purchaseBillReceiptService.add(purchaseBillReceipt);
        return JsonResult.success("添加成功");
    }

}
